package com.apexedu.biz.entity;

import com.apexedu.framework.util.SeqFactory;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * 定时器执行日志
 * Created by ly on 2015/8/12.
 */
@Entity
@Table(name = "T_TIMER_LOG")
public class TTimerLog implements Serializable {
    private String wid;
    private String tid; //定时器id  t_timer表id
    private Date nexttime; //下次执行时间
    private Date lasttime; //上次执行时间
    private Long executesecond; //上次执行时长（秒数）
    private String errorlog; //错误日志
    private String state; //上次执行状态 1为完成/未执行 0为报错

    public TTimerLog() {
        this.wid = SeqFactory.getNewSequenceAlone();
        this.lasttime = new Date();
    }

    public TTimerLog(Integer s) {
        if(s == -1){
            this.wid = SeqFactory.getNewSequenceAlone();
            this.state = "1";
        }
    }

    @Id
    @Column(name = "WID")
    public String getWid() {
        return wid;
    }

    public void setWid(String wid) {
        this.wid = wid;
    }

    @Basic
    @Column(name = "TID")
    public String getTid() {
        return tid;
    }

    public void setTid(String tid) {
        this.tid = tid;
    }

    @Basic
    @Column(name = "NEXTTIME")
    public Date getNexttime() {
        return nexttime;
    }

    public void setNexttime(Date nexttime) {
        this.nexttime = nexttime;
    }

    @Basic
    @Column(name = "LASTTIME")
    public Date getLasttime() {
        return lasttime;
    }

    public void setLasttime(Date lasttime) {
        this.lasttime = lasttime;
    }

    @Basic
    @Column(name = "EXECUTESECOND")
    public Long getExecutesecond() {
        return executesecond;
    }

    public void setExecutesecond(Long executesecond) {
        this.executesecond = executesecond;
    }

    @Basic
    @Column(name = "ERRORLOG")
    public String getErrorlog() {
        return errorlog;
    }

    public void setErrorlog(String errorlog) {
        if(errorlog.length()>3000){
            this.errorlog = errorlog.substring(0,3000);
        }else{
            this.errorlog = errorlog;
        }
    }

    @Basic
    @Column(name = "STATE")
    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    @Override
    public String toString() {
        return "TTimerLog{" +
                "wid='" + wid + '\'' +
                ", tid='" + tid + '\'' +
                ", nexttime=" + nexttime +
                ", lasttime=" + lasttime +
                ", executesecond=" + executesecond +
                ", errorlog='" + errorlog + '\'' +
                ", state='" + state + '\'' +
                '}';
    }
}
